#include "stdafx.h"
#include "qgraphicsitemquestionfullscreen.h"
#include "memorygame.h"

QBrush QGraphicsItemQuestionFullScreen::m_backroundBrushQuestion( QColor( 0, 80, 80 ) );
QBrush QGraphicsItemQuestionFullScreen::m_backroundBrushAnswer( QColor( 0, 220, 220 ) );
QFont QGraphicsItemQuestionFullScreen::m_font( "Times", 20 );

QGraphicsItemQuestionFullScreen::QGraphicsItemQuestionFullScreen( int x, int y, int width, int height, MemoryGame & parent )
:   QGraphicsRectItem( x, y, width, height ),
    m_parent( parent ),
    m_questionMode( true )
{

}

QGraphicsItemQuestionFullScreen::~QGraphicsItemQuestionFullScreen()
{

}

void QGraphicsItemQuestionFullScreen::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
{
    QRectF r( rect() );
    QString * str;
    QBrush * brush;
    if (m_questionMode)
    {
        str = & m_question.question;
        brush = & m_backroundBrushQuestion;
    }
    else
    {
        str = & m_question.answer;
        brush = & m_backroundBrushAnswer;
    }

    painter->setBrush( * brush );
    painter->drawRect( r );
    painter->setFont( m_font );
    QFontMetrics fontMetrics( m_font );
    painter->drawText( r, * str );
}

void QGraphicsItemQuestionFullScreen::setQuestionMode( bool questionMode )
{
    m_questionMode = questionMode;
    update();
}

bool QGraphicsItemQuestionFullScreen::isQuestionMode() const
{
    return m_questionMode;
}

void QGraphicsItemQuestionFullScreen::setQuestion( const Question & question )
{
    m_question = question;
}

void QGraphicsItemQuestionFullScreen::mouseDoubleClickEvent( QGraphicsSceneMouseEvent * event )
{
    if (! m_questionMode)
        hide();
}